package view;

import controller.*;
import javax.swing.JOptionPane;

/**
 *
 * @author tobias
 */
public class ManagerPanel extends javax.swing.JPanel {
    private Controller ctrl;

    private StartPanel startPanel;
    private ContactPanel contactPanel;
    private EventPanel eventPanel;
    private JournalPanel journalPanel;
    private LinkPanel linkPanel;
    private MemoPanel memoPanel;
    private PasswordPanel passPanel;
    private ResearchPanel researchPanel;

    /**
     * Creates a new ManagerPanel with a controller and tabs.
     * @param ctrl
     * @param contactPanel
     * @param eventPanel
     * @param journalPanel
     * @param linkPanel
     * @param memoPanel
     * @param passPanel
     * @param researchPanel
     */
    public ManagerPanel(Controller ctrl, StartPanel startPanel, ContactPanel contactPanel, EventPanel eventPanel, JournalPanel journalPanel, LinkPanel linkPanel, MemoPanel memoPanel, PasswordPanel passPanel, ResearchPanel researchPanel) {
        initComponents();
        this.ctrl = ctrl;
        this.startPanel = startPanel;
        this.contactPanel = contactPanel;
        this.eventPanel = eventPanel;
        this.journalPanel = journalPanel;
        this.linkPanel = linkPanel;
        this.memoPanel = memoPanel;
        this.passPanel = passPanel;
        this.researchPanel = researchPanel;

        tabPane.addTab("Startside", startPanel);
        tabPane.addTab("Kontaktpersoner", contactPanel);
        tabPane.addTab("Aftaler", eventPanel);
        tabPane.addTab("Dagbog", journalPanel);
        tabPane.addTab("Links", linkPanel);
        tabPane.addTab("Huskesedler", memoPanel);
        tabPane.addTab("Kodeord", passPanel);
        tabPane.addTab("Research", researchPanel);
    }

    public void addMenuBar() {
        ctrl.getFrame().setJMenuBar(menuBar);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        saveMenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        exitMenuItem = new javax.swing.JMenuItem();
        toolsMenu = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        contactsMenuItem = new javax.swing.JMenuItem();
        eventsMenuItem = new javax.swing.JMenuItem();
        journalMenuItem = new javax.swing.JMenuItem();
        linksMenuItem = new javax.swing.JMenuItem();
        memosMenuItem = new javax.swing.JMenuItem();
        passwordsMenuItem = new javax.swing.JMenuItem();
        researchMenuItem = new javax.swing.JMenuItem();
        maintenanceMenu = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JSeparator();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        titleLabel = new javax.swing.JLabel();
        tabPane = new javax.swing.JTabbedPane();

        fileMenu.setText("Filer");

        saveMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        saveMenuItem.setText("Gem alle data");
        saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(saveMenuItem);
        fileMenu.add(jSeparator1);

        exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        exitMenuItem.setText("Afslut");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        toolsMenu.setText("Funktioner");

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_0, java.awt.event.InputEvent.ALT_MASK));
        jMenuItem1.setText("Startside");
        toolsMenu.add(jMenuItem1);
        toolsMenu.add(jSeparator2);

        contactsMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_1, java.awt.event.InputEvent.ALT_MASK));
        contactsMenuItem.setText("Kontakter");
        contactsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                contactsMenuItemActionPerformed(evt);
            }
        });
        toolsMenu.add(contactsMenuItem);

        eventsMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_2, java.awt.event.InputEvent.ALT_MASK));
        eventsMenuItem.setText("Aftaler");
        eventsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                eventsMenuItemActionPerformed(evt);
            }
        });
        toolsMenu.add(eventsMenuItem);

        journalMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_3, java.awt.event.InputEvent.ALT_MASK));
        journalMenuItem.setText("Dagbog");
        journalMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                journalMenuItemActionPerformed(evt);
            }
        });
        toolsMenu.add(journalMenuItem);

        linksMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_4, java.awt.event.InputEvent.ALT_MASK));
        linksMenuItem.setText("Links");
        linksMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                linksMenuItemActionPerformed(evt);
            }
        });
        toolsMenu.add(linksMenuItem);

        memosMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_5, java.awt.event.InputEvent.ALT_MASK));
        memosMenuItem.setText("Huskesedler");
        memosMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                memosMenuItemActionPerformed(evt);
            }
        });
        toolsMenu.add(memosMenuItem);

        passwordsMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_6, java.awt.event.InputEvent.ALT_MASK));
        passwordsMenuItem.setText("Kodeord");
        passwordsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                passwordsMenuItemActionPerformed(evt);
            }
        });
        toolsMenu.add(passwordsMenuItem);

        researchMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_7, java.awt.event.InputEvent.ALT_MASK));
        researchMenuItem.setText("Research");
        researchMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                researchMenuItemActionPerformed(evt);
            }
        });
        toolsMenu.add(researchMenuItem);

        menuBar.add(toolsMenu);

        maintenanceMenu.setText("Vedligeholdelse");

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setText("Fjern gamle aftaler");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        maintenanceMenu.add(jMenuItem2);

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem3.setText("Fjern gamle huskesedler");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        maintenanceMenu.add(jMenuItem3);
        maintenanceMenu.add(jSeparator3);

        jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem4.setText("Sorter aftaler efter dato");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        maintenanceMenu.add(jMenuItem4);

        jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem5.setText("Sorter kontakter efter navn");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        maintenanceMenu.add(jMenuItem5);

        menuBar.add(maintenanceMenu);

        titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | java.awt.Font.BOLD, titleLabel.getFont().getSize()+3));
        titleLabel.setText("LifeManager");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(titleLabel))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(20, 20, 20)
                        .add(tabPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 692, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(titleLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(tabPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
}//GEN-LAST:event_exitMenuItemActionPerformed

    private void contactsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_contactsMenuItemActionPerformed
        tabPane.setSelectedComponent(contactPanel);
}//GEN-LAST:event_contactsMenuItemActionPerformed

    private void eventsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_eventsMenuItemActionPerformed
        tabPane.setSelectedComponent(eventPanel);
    }//GEN-LAST:event_eventsMenuItemActionPerformed

    private void journalMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_journalMenuItemActionPerformed
        tabPane.setSelectedComponent(journalPanel);
    }//GEN-LAST:event_journalMenuItemActionPerformed

    private void linksMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_linksMenuItemActionPerformed
        tabPane.setSelectedComponent(linkPanel);
    }//GEN-LAST:event_linksMenuItemActionPerformed

    private void memosMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_memosMenuItemActionPerformed
        tabPane.setSelectedComponent(memoPanel);
    }//GEN-LAST:event_memosMenuItemActionPerformed

    private void passwordsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_passwordsMenuItemActionPerformed
        tabPane.setSelectedComponent(passPanel);
    }//GEN-LAST:event_passwordsMenuItemActionPerformed

    private void researchMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_researchMenuItemActionPerformed
        tabPane.setSelectedComponent(researchPanel);
    }//GEN-LAST:event_researchMenuItemActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        if(JOptionPane.showConfirmDialog(ctrl.getFrame(), "Denne funktion vil slette alle aftaler der er ældre end dags dato. Vil du fortsætte?", "Slet aftaler", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            int counter = ctrl.cleanupEvents();
            JOptionPane.showMessageDialog(ctrl.getFrame(), "Der blev fjernet " + String.valueOf(counter) + " aftaler.", "Aftaler fjernet", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        if(JOptionPane.showConfirmDialog(ctrl.getFrame(), "Denne funktion vil slette alle huskesedler der er ældre end dags dato. Vil du fortsætte?", "Slet huskesedler", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            int counter = ctrl.cleanupMemos();
            JOptionPane.showMessageDialog(ctrl.getFrame(), "Der blev fjernet " + String.valueOf(counter) + " huskesedler.", "Huskesedler fjernet", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        if(JOptionPane.showConfirmDialog(ctrl.getFrame(), "Denne funktion vil sortere alle dine aftaler efter startdato. Vil du fortsætte?", "Sorter aftaler", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            ctrl.sortEvents();
        }
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuItemActionPerformed
        if(ctrl.saveUManager()) {
            JOptionPane.showMessageDialog(ctrl.getFrame(), "Alle data blev gemt på harddisken. Programmet gemmer automatisk dine data ved afslutning.", "Data gemt", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_saveMenuItemActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        if(JOptionPane.showConfirmDialog(ctrl.getFrame(), "Denne funktion vil sortere alle dine kontaktpersoner alfabetisk efter fornavn. Vil du fortsætte?", "Sorter kontakter", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            ctrl.sortContacts();
        }
    }//GEN-LAST:event_jMenuItem5ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem contactsMenuItem;
    private javax.swing.JMenuItem eventsMenuItem;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JMenuItem journalMenuItem;
    private javax.swing.JMenuItem linksMenuItem;
    private javax.swing.JMenu maintenanceMenu;
    private javax.swing.JMenuItem memosMenuItem;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem passwordsMenuItem;
    private javax.swing.JMenuItem researchMenuItem;
    private javax.swing.JMenuItem saveMenuItem;
    private javax.swing.JTabbedPane tabPane;
    private javax.swing.JLabel titleLabel;
    private javax.swing.JMenu toolsMenu;
    // End of variables declaration//GEN-END:variables

}
